/*
 * common.h
 *
 *  Created on: 28 nov. 2013
 *      Author: SAGUET Julien et POCREAU Aymeric
 */

#ifndef COMMON_H_
#define COMMON_H_

#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <netinet/in.h>

#include "../includes/server.h"

#define BACKLOG 1024
#define MAXBUF 1024

int create_socket(int ip, int port);
void checkAction(listeClients liste, client_t* Client, char* buffer, groupe_t** listeGroupes, ban_t** listebans);
char* new_client_name(int socket, listeClients liste);
void sendRequest(char* message, client_t* Client, listeClients liste);
void getNames(listeClients liste, int socket);
void getGrNames(listeClients liste, int socket, int idGroup);
int sendToName(listeClients liste, char* message, client_t* from);
int pseudoExiste(listeClients liste, const char *Pseudo);
int sendline(int fd, const void *str, size_t maxlen);
int readline(int fd, void *str, int max_len);
listeClients ajouterClient(listeClients liste, int socket, char* Pseudo, struct sockaddr_in client);
listeClients deleteFromList(int Socket, listeClients liste);
void sendtoAll(listeClients liste, client_t* Client, char* buffer);
int checkBlackList(client_t* clientTo, client_t* clientFrom);
int checkBlackListGroup(groupe_t* groupe, client_t* clientFrom);
void ajouterBlackList(listeClients liste, client_t* client, char* buffer);
void group(groupe_t** listeGroupes, client_t* client, char* buffer);
void sendtoGroup(groupe_t** listeGroupes, listeClients liste, client_t* Client, char* buffer);
void banGroup(groupe_t** listeGroupes, listeClients liste, client_t* Client, char* buffer);
void gestionComptes(int conn_s, char* pseudo);
void creationCompte(pid_t conn_s, FILE **file, char *pseudo);
int authentification(pid_t conn_s, FILE **file, char *mdp_lu);
void kick(listeClients liste, char* buffer);
void ban(ban_t** listebans, listeClients liste, char* buffer);
void administrer(client_t* client);
listeClients deleteFromList(int Socket, listeClients liste);

#endif /* COMMON_H_ */
